{include file="public/header" type="other"/}
<form class="layui-form" action="">
    <div class="mainBox">
        <div class="main-container">
                <div class="layui-form-item">
                    <label class="layui-form-label">
                        接口类型
                    </label>
                    <div class="layui-input-block">
                        <select name="type" lay-filter="type">
                            <option value="polymerization">聚合登录</option>
                            <option value="qq">QQ登录</option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item" id="recommend">
                    <label class="layui-form-label">
                        推荐对接
                    </label>
                    <div class="layui-input-block">
                        <select name="recommend" lay-filter="recommend">
                            <option value="">请选择要对接的聚合平台,自定义无需选择此项</option>
                            <?php foreach ($LoginAd as $value): ?>
		                        <option value="{$value.url}">{$value.title}</option>
		                    <?php endforeach; ?> 
                        </select>
                    </div>
                </div>
                                                    
                <div class="layui-form-item">
                    <label class="layui-form-label">
                        对接站名称
                    </label>
                    <div class="layui-input-block">
                        <input type="text" class="layui-input layui-form-danger" id="name" name="name"  placeholder="请输入通道名称"/>
                    </div>
                </div>
                <div class="layui-form-item" id="api">
                    <label class="layui-form-label">
                        API
                    </label>
                    <div class="layui-input-block">
                        <input type="text" class="layui-input layui-form-danger" id="url" name="url" placeholder="请输入API地址"/>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">
                        APPID
                    </label>
                    <div class="layui-input-block">
                        <input type="text" class="layui-input layui-form-danger" name="appid"  placeholder="请输入APPPID"/>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">
                        APPKEY
                    </label>
                    <div class="layui-input-block">
                        <input type="text" class="layui-input layui-form-danger" name="appkey"  placeholder="请输入APPKEY"/>
                    </div>
                </div>
                <div class="layui-form-item" style="display:none;" id="QQNotify">
                    <label class="layui-form-label">
                        回调地址 
                    </label>
                    <div class="layui-input-block">
                        <p class="layui-form-label">{$Request.domain}/Notify/qqcallback</p>
                    </div>
                </div>
        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="layui-btn layui-btn-normal layui-btn-sm" lay-submit="" lay-filter="save">
               
                提交
            </button>
            <button type="reset" class="layui-btn layui-btn-primary layui-btn-sm">
               
                重置
            </button>
        </div>
    </div>
</form>
{include file="public/footer"/}
<script>
    layui.use(['form', 'jquery'], function () {
        let form = layui.form;
        let $ = layui.jquery;
        //登录通道筛选
        form.on('select(type)', function(data) {
 			let value = data.value;
 			$("#api").show();
 			$("#recommend").show();
 			$("#QQNotify").hide();
 			if(value == "qq"){
 			    $("#api").hide();
 			    $("#recommend").hide();
 			    $("#QQNotify").show();
 			}
 			
 			return false;
 		});
 		
 		//下拉获取参数
 		form.on('select(recommend)', function(data) {
 			$('#url').val(data.value);
 			$('#name').val($("#recommend option:selected").text());
 		});
 		
        
        form.on('submit(save)', function (data) {
            
            $.ajax({
                data: JSON.stringify(data.field),
                dataType: 'json',
                contentType: 'application/json',
                type: 'post',
                success: function (res) {
                    //判断有没有权限
                    if (res && res.code == 999) {
                        layer.msg(res.msg, {
                            icon: 5,
                            time: 2000,
                        })
                        return false;
                    } else if (res.code == 200) {
                        layer.msg(res.msg,{icon:1,time:1000}, function () {
                            parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
                            parent.layui.table.reload("dataTable");
                        });
                    } else {
                        layer.msg(res.msg,{icon:2,time:1000});
                    }
                }
            })
            return false;
        });
    })
</script>
</body>
</html>